package com.gamex.findit.service.impl;

import java.util.HashMap;
import java.util.concurrent.ExecutorService;

import org.jboss.netty.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gamex.findit.dao.BattleMapper;
import com.gamex.findit.service.BattleService;

/**
 * 소켓 서비스
 * @author james
 *
 */
@Service
public class BattleServiceImpl implements BattleService {
	
	private static final Logger logger = LoggerFactory.getLogger(BattleServiceImpl.class);
	
	@Autowired BattleMapper battleMapper;
	
	@Override
	public String getWaitMemeber(String userId) throws Exception {
		String result = null;
		try {
			result = battleMapper.selectWaitMemeber(userId);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return result;
	}

	@Override
	public String createGameRoom(String userId) throws Exception {
		String result = null;
		try {
			result = battleMapper.insertGameRoom(userId);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return result;
	}

	@Override
	public String outGameRoom(String id, String gameId) throws Exception {
		String result = null;
		try {
			HashMap<String, String> param = new HashMap<String, String>();
			param.put("game_id", gameId);
			param.put("id", id);
			
			result = battleMapper.outGameRoom(param);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return result;
	}

	@Override
	public String joinGameRoom(String id, String gameId) throws Exception {
		String result = null;
		try {
			HashMap<String, String> param = new HashMap<String, String>();
			param.put("id", id);
			param.put("gameId", gameId);
			result = battleMapper.joinGameRoom(param);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return result;
	}

	@Override
	public void outListen(String id) throws Exception {
		try {
			battleMapper.outListen(id);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		
	}

	@Override
	public String readyGameRoom(String id, String clientId) throws Exception {
		String result = null;
		try {
			HashMap<String, String> param = new HashMap<String, String>();
			param.put("id", id);
			param.put("clientId", clientId);
			
			result = battleMapper.readyGameRoom(param);
		} catch (Exception e) {
			logger.error(e.getMessage());
		}
		return result;
	}

	@Override
	public String searchGame(String userId) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
